package com.lzw.okgoutils.http.otherutils;

import android.content.Context;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;

/**
 * 文件操作工具类
 */
public class FileUtils {

    /**
     * 读取文件内容
     * @param context
     * @param fileName
     * @return
     */
    public static String readFile(Context context, String fileName) {
        String res = null;
        try {
            InputStream is = context.getAssets().open(fileName);
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            byte[] data = new byte[1024];
            int count = 0;
            while ((count = is.read(data)) != -1) {
                bos.write(data, 0, count);
            }
            res = new String(bos.toByteArray(), "UTF-8");
            is.close();
            bos.close();
        } catch (IOException e) {
            e.printStackTrace();
            LogUtil.printExceptions(e);
        }
        return res;
    }
}
